<template>
  <el-container class="home-container">
    <!-- 头部区域 -->
    <el-header>
      <div>
        <img src="../assets/py-logo.png" alt="" />
        <span @click="handleLogoLink">业绩管理系统</span>
      </div>
      <!-- 设置 -->
      <div class="setting">
        <el-dropdown>
          <div class="imgbox">
            <el-button
              type="warning"
              icon="el-icon-error"
              circle
              @click="handleLogoLink"
            ></el-button>
          </div>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item><div @click="logout">退出</div></el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </el-header>
    <!-- 页面主体区域 -->
    <el-container>
      <!-- 左侧列表区域 -->
      <!-- 侧边栏  -->
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <!-- 实现折叠展开 -->
        <div class="toggle-button" @click="toggleCollapse">|||</div>
        <!-- 侧边栏菜单区域 -->
        <!-- unique-opened 只展开一项 -->
        <el-menu
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409EFF"
          :collapse="isCollapse"
          :collapse-transition="false"
          :default-active="activePath"
        >
          <!-- 一级菜单 -->
          <el-submenu
            :index="item.id.toString()"
            v-for="item in menuList"
            :key="item.id"
          >
            <!-- 一级菜单的模板区域 -->
            <template slot="title">
              <!-- 图标 -->
              <i :class="item.icon"></i>
              <!-- 文本 -->
              <span>{{ item.name }}</span>
            </template>

            <!-- 二级菜单 -->
            <el-menu-item
              :index="'/admin/' + child.path"
              v-for="child in item.children"
              :key="child.id"
              @click="handleChildLinkClick(child.path)"
            >
              <template slot="title">
                <!-- 图标 -->
                <i class="el-icon-menu"></i>
                <!-- 文本 -->
                <span>{{ child.name }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 右侧内容主体 -->
      <el-main>
        <!-- 路由占位符 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import { mapState, mapMutations, mapActions } from "vuex";
export default {
  name: "myAdmin",
  data() {
    return {
      isCollapse: false,
      activePath: "",
      menuList: [
        {
          name: "用户管理",
          id: 1,
          icon: "el-icon-s-custom",
          children: [
            { name: "用户列表", id: 1, path: "userList" },
            { name: "人员管理", id: 2, path: "crewManage" },
          ],
        },
        {
          name: "业绩管理",
          id: 2,
          icon: "el-icon-s-check",
          children: [
            { name: "业绩列表", id: 1, path: "achievementList" },
            { name: "业绩办理", id: 2, path: "achievementTransaction" },
          ],
        },
      ],
    };
  },
  methods: {
    ...mapActions(["getSubject_classificationList", "getCollegeList"]),
    handleLogoLink() {
      this.$router.push(
        {
          path: "/admin",
        },
        () => {},
        () => {}
      );
    },
    logout() {
      this.$router.push(
        {
          path: "/admin",
        },
        () => {},
        () => {}
      );
    },
    logout() {
      window.localStorage.clear();
      this.$router.push("/login").catch(() => {});
      // console.log(1);
    },
    toggleCollapse() {
      this.isCollapse = !this.isCollapse;
    },
    handleChildLinkClick(path) {
      this.$router
        .push({
          name: path,
        })
        .catch(() => {});
    },
  },
  created() {
    this.activePath = this.$route.path;
    let _this = this;
    this.getCollegeList({ _this });
    this.getSubject_classificationList({ _this });
  },
};
</script>

<style lang="less" scoped>
.home-container {
  height: 100%;
}

.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  padding-left: 3%;
  align-items: center;
  color: #fff;
  font-size: 20px;
  > div {
    width: 20%;
    display: flex;
    align-items: center;

    img {
      margin-right: 2%;
    }

    span {
      margin-left: 1%;
    }
  }
}
.el-main {
  background-color: #eaedf1;
  padding: 0 !important;
}
.el-aside {
  transition: 0.2s ease;
  background-color: #333744;
  .el-menu {
    border-right: none;
  }
}

.iconfont {
  margin-right: 10px;
}

.toggle-button {
  background-color: #4a5064;
  font-size: 10px;
  line-height: 24px;
  color: #fff;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
}
</style>